﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cotizav.CONTROLADOR;
using Cotizav.CONEXION.DataSet;
using Microsoft.Reporting.WinForms;

namespace Cotizav.PRESENTACION.CartaCompromiso.Reporte
{
    public partial class ReporteCartaCompromiso : Form
    {
        private CtrlCartaCompromiso ctCartaCompromiso;
        private CtrlCartaCompromisoDetalle ctCartaDetalle;

        private string idCartaCompromiso;

        public ReporteCartaCompromiso()
        {
            InitializeComponent();

            ctCartaCompromiso = new CtrlCartaCompromiso();
            ctCartaDetalle = new CtrlCartaCompromisoDetalle();
        }

        public ReporteCartaCompromiso(string idCartaCompromiso) : this()
        {
            // TODO: Complete member initialization
            this.idCartaCompromiso = idCartaCompromiso;
        }

        private void ReporteCartaCompromiso_Load(object sender, EventArgs e)
        {
            DataSetCotizav.usp_listarCartaCompromisoDataTable dtCartaCompromiso = this.loadDS_CartaCompromiso(idCartaCompromiso);
            DataSetCotizav.usp_listarCartaCompromisoDetalleDataTable dtCartaDetalle = this.loadDS_CartaCompromisoDetalle(idCartaCompromiso);

            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ds_CartaCompromiso", dtCartaCompromiso.ToList()));
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ds_CartaCompromisoDetalle", dtCartaDetalle.ToList()));

            this.reportViewer1.RefreshReport();
        }

        private DataSetCotizav.usp_listarCartaCompromisoDataTable loadDS_CartaCompromiso(string idCartaCompromiso)
        {
            DataSetCotizav.usp_listarCartaCompromisoDataTable dt = new DataSetCotizav.usp_listarCartaCompromisoDataTable();

            if (!string.IsNullOrWhiteSpace(idCartaCompromiso))
            {
                DataTable dtResult = ctCartaCompromiso.getListCartaCompromisoSP(idCartaCompromiso);

                foreach (DataRow dr in dtResult.Rows)
                {
                    dt.Rows.Add
                        (
                            dr[0].ToString(),
                            dr[1].ToString(),
                            dr[2].ToString(),
                            dr[3].ToString(),
                            dr[4].ToString(),
                            dr[5].ToString(),
                            dr[6].ToString(),
                            dr[7].ToString(),
                            dr[8].ToString(),
                            dr[9].ToString(),
                            dr[10].ToString()
                        );
                }
            }

            return dt;
        }

        private DataSetCotizav.usp_listarCartaCompromisoDetalleDataTable loadDS_CartaCompromisoDetalle(string idCartaCompromiso)
        {
            DataSetCotizav.usp_listarCartaCompromisoDetalleDataTable dt = new DataSetCotizav.usp_listarCartaCompromisoDetalleDataTable();

            if (!string.IsNullOrWhiteSpace(idCartaCompromiso))
            {
                DataTable dtResult = ctCartaDetalle.getListCartacompromisoDetalleSP(idCartaCompromiso);

                foreach (DataRow dr in dtResult.Rows)
                {
                    dt.Rows.Add
                        (
                            dr[0].ToString(),
                            dr[1].ToString(),
                            dr[2].ToString(),
                            dr[3].ToString(),
                            dr[4].ToString(),
                            dr[5].ToString(),
                            dr[6].ToString()
                        );
                }
            }

            return dt;
        }
    }
}
